package com.ruoyi.produce.base.mould.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.produce.base.mould.domain.Mould;
import com.ruoyi.produce.base.mould.domain.MouldCond;
import com.ruoyi.produce.base.mould.service.IMouldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 模具管理
 */
@RestController
@RequestMapping("/produce/mould")
@Api(value = "模具管理模块", tags = "模具管理接口")
public class MouldController extends BaseController {
    @Autowired
    private IMouldService mouldService;

    /**
     * 获取模具管理
     * @param cond
     * @return
     */
    @ApiOperation(value = "获取模具管理列表",notes = "查询所有模具管理信息")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody MouldCond cond) {
        startPage();
        List<Mould> mouldList = mouldService.selectMouldList(cond);
        return getDataTable(mouldList);
    }

    /**
     * 导出模具管理
     *
     * @param cond
     * @return
     */
    @PostMapping("/export")
    public AjaxResult export(@RequestBody MouldCond cond) {
        List<Mould> mouldList = mouldService.selectMouldList(cond);
        ExcelUtil<Mould> util = new ExcelUtil<>(Mould.class);
        return util.exportExcel(mouldList, "模具信息");
    }

    /**
     * 新增模具管理
     * @param mould
     * @return
     */
    @ApiOperation(value = "新增模具管理", notes = "新增模具管理信息")
    @ApiImplicitParam(name = "mould", value = "新增模具管理", dataType = "Mould")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Mould mould) {
        try {
            mouldService.insertMould(mould);
            return AjaxResult.success("新增成功");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("新增失败");
        }
    }

    /**
     *
     * 更新模具管理
     * @param mould
     * @return
     */
    @ApiOperation(value = "修改模具管理", notes = "修改模具管理")
    @ApiImplicitParam(name = "mould", value = "修改模具管理", dataType = "Mould")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Mould mould) {
        try {
            mouldService.updateMould(mould);
            return AjaxResult.success("修改成功");
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error("修改失败");
        }
    }

    /**
     * 删除模具管理
     * 仅修改删除标志位
     * @param mould
     * @return
     */
    @ApiOperation(value = "删除模具管理", notes = "删除模具管理,仅删除标志位")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Mould mould) {

        return toAjax(mouldService.updateMouldDeleteFlag(mould));
    }
}
